package com.cn.hospital.config;

import com.cn.haspital.config.interceptor.WholeTokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器:
 * 拦截路径配置
 */

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    /**
     * 提前加载AuthorizeInterceptor拦截器
     * 否则AuthorizeInterceptor拦截器Autowired注解注入为null
     *
     * @return
     */
    @Bean
    public HandlerInterceptor getWholeTokenInterceptor() {
        return new WholeTokenInterceptor();
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getWholeTokenInterceptor())
                .addPathPatterns("/**")                     //所有路径都被拦截
                .excludePathPatterns(                       //添加不拦截路径
                        "/register",                        //注册
                        "/login",                           //登录
                        "/logout",                          //登出
                        "/static/**",                       //静态资源
                        "/assets/**"                        //静态资源
                );
    }
}
